package com.JZ.QM.controller;

import com.JZ.QM.common.utils.CommonResult;
import com.JZ.QM.service.CounselorInfoService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author lyp
 * @email lyp@gmail.com
 * @date 2020/6/15 9:13
 */

@RefreshScope
@RestController
@RequestMapping("/management/counselor")
public class CounselorController {

    @Resource
    private CounselorInfoService counselorInfoService;

    /**
     * 登录功能
     * @param accountCode,password
     */
    @RequestMapping("/login")
    public CommonResult login(String accountCode,String password){

        //检查登录是否成功
        boolean loginFlag = counselorInfoService.login(accountCode, password);
        //获取cookie需要的属性
        Map<String,String> cookieMap = counselorInfoService.getCookie(accountCode);

        if(true == loginFlag) {
            return CommonResult.success().put("name",cookieMap.get("name")).put("id",cookieMap.get("id"));
        }else {
            return CommonResult.error(201,"账号名和密码不符合");
        }
    }
}
